﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Three.BookStore.LoginERP;
using Volo.Abp.Domain.Repositories;

namespace Three.BookStore.RBAC
{
    public class Permissions : IPermissions
    {
        IRepository<PermissionModel> _repositoryPermiss;

        public Permissions(IRepository<PermissionModel> repositoryPermiss)
        {
            _repositoryPermiss = repositoryPermiss;
        }

        public async Task<int> CreatePermissionAsync(PermissionModel permission)
        {
            await _repositoryPermiss.InsertAsync(permission);
            return 1;
        }

        public async Task<int> DeletePermissionAsync(int id)
        {
            await _repositoryPermiss.DeleteAsync(x => x.Id == id);
            return 1;
        }

        public async Task<List<PermissionModel>> GetAllPermissionsAsync()
        {
            return await _repositoryPermiss.GetListAsync();
        }

        public async Task<PermissionModel> GetPermissionByIdAsync(int id)
        {
            return await _repositoryPermiss.GetAsync(x=>x.Id==id);
        }

        public async Task<int> UpdatePermissionAsync(PermissionModel permission)
        {
            await _repositoryPermiss.UpdateAsync(permission);
            return 1;
        }
    }
}
